'use client';

import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useSession } from '@/lib/auth-client';
import LoadingSpinner from '@/components/ui/LoadingSpinner';

export default function RedirectToDashboard() {
  const router = useRouter();
  const { data: session, isPending } = useSession();

  useEffect(() => {
    if (!isPending) {
      if (session?.user?.id) {
        // 如果用户已登录，重定向到dashboard
        router.replace(`/${session.user.id}/dashboard`);
      } else {
        // 如果用户未登录，重定向到登录页面
        router.replace('/auth/login');
      }
    }
  }, [session, isPending, router]);

  // 显示加载状态
  return (
    <div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100 dark:from-slate-900 dark:to-slate-800">
      <div className="text-center">
        <LoadingSpinner size="lg" />
        <p className="mt-4 text-lg text-muted-foreground">正在重定向到控制台...</p>
      </div>
    </div>
  );
} 